package com.springbootjsp.service.impl;

import com.springbootjsp.mapper.UserTestMapper;
import com.springbootjsp.model.User;
import com.springbootjsp.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: szw
 * @Date: 2021/6/10 17:49
 */
@Service
public class TestServiceImpl implements TestService {
    @Autowired
    UserTestMapper userTestMapper;

    @Override
    public List<User> findall() {
        List<User> findall = userTestMapper.findall();
        return findall;
    }

    /*用户登录*/
    @Override
    public List<User> login(User user) {
        List<User> login = userTestMapper.login(user);
        if(login!=null){
            return login;
        }
        return null;
    }

    @Override
    public boolean findById(String name) {
        List<User> byId = userTestMapper.findById(name);
        if(!byId.isEmpty()){
            return false;
        }
        return true;
    }

    /*用户注册*/
    @Override
    public boolean insertUser(User user) {
        boolean byId = findById(user.getUser_account());
        if(byId){
            int i = userTestMapper.insertUser(user);
            System.out.println(i);
            if(i!=0){
                return true;
            }
        }
        return false;
    }
}
